package com.shujia.wyh.utils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.PreparedStatement;

public class ExtendDataDemo {
    public static void main(String[] args) throws Exception {
        //获取数据库连接对象
        Connection conn = MysqlTool.getConnection();

        BufferedReader br = null;

        //获取数据库预编译对象
        PreparedStatement statement = conn.prepareStatement("insert into students values(?,?,?,?,?)");

        for (int i = 21; i <= 1000; i++) {
            //创建字符缓冲输入流对象
            br = new BufferedReader(new FileReader("E:\\projects\\IDEAProjects\\bigdata23-project\\bigdata23-project\\bigdata23-jdbc\\src\\main\\java\\com\\shujia\\wyh\\datas\\students.txt"));
            String line = null;
            while ((line = br.readLine()) != null) {
                String[] split = line.split(",");
                String id = split[0] + "-" + i; //1500100001-2
                String name = split[1];
                String age = split[2];
                String gender = split[3];
                String clazz = split[4];
                statement.setString(1, id);
                statement.setString(2, name);
                statement.setString(3, age);
                statement.setString(4, gender);
                statement.setString(5, clazz);

                //执行sql语句
                statement.executeUpdate();
            }
            br.close();
        }
        System.out.println("数据扩大完毕！！");

        statement.close();
        conn.close();

    }
}
